#pragma once
#include <vector>
#include <fstream>

//-------------------------------------------------------------------------------------------------
bool FileSave(const char *filename, const void *data, size_t count, bool append = false);

//-------------------------------------------------------------------------------------------------
bool FileLoad(const char *filename, void *data, size_t count);


//-------------------------------------------------------------------------------------------------
template<typename T>
bool FileSave(const char *filename, const std::vector<T> &data)
{
	return FileSave(filename, &data[0], data.size()*sizeof(T));
}


//-------------------------------------------------------------------------------------------------
template<typename T>
bool FileLoad(const char *filename, std::vector<T> &data)
{
//----
//	load data from disk
	std::ifstream file(filename, std::ios::in | std::ios::binary);


	if(!file.good())
	{
		file.close();
		return false;
	}

	file.seekg(0, std::ios::end);
	size_t size = (size_t)file.tellg();

	if(data.size()*sizeof(T) != size)
		data.resize(size/sizeof(T) + (size%sizeof(T) ? 1 : 0));

	file.seekg(std::ios::beg);
	file.read((char *) &data[0], size);
	file.close();

	return true;
}

